package photostock.model.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import photostock.model.Album;
import photostock.model.User;

public class AlbumTest {

	@Test
	public void testExistingAlbum() {
		User user = new User("nico");
		assertTrue (user.exists() && user.isDirectory() && !user.create());
		assertTrue(user.getLogin().equals("nico"));
		assertTrue(user.login("atreides"));
		assertTrue(user.initChildrenItems());
		Album album = (Album)user.getChildrenItems().elementAt(0);
		assertTrue(album.getChildrenItems().size() == 0);
		assertTrue(album.initChildrenItems());
		assertTrue(album.getChildrenItems().size() == 14);
		assertEquals(album.getName(), "Martinique");
		assertEquals(album.getId(), 0);
		assertEquals(album.getTheme(), "Vacances");
		assertEquals(album.getParentItem().getName(), "nico");
		assertEquals(album.getSkin(), "default.css");
	}
	
	@Test
	public void testNewAlbum() {
		
		User user = new User("nico");
		assertTrue (user.exists() && user.isDirectory() && !user.create());
		assertTrue(user.getLogin().equals("nico"));
		assertTrue(user.login("atreides"));
		assertTrue(user.initChildrenItems());
		assertTrue(user.createAlbum("test"));
		Album album = (Album)user.getChildrenItems().elementAt(1);
		assertTrue (album.exists() && album.isDirectory() && !album.create());
		assertEquals(user.getChildrenItems().size(), 2);
		assertFalse(album.initChildrenItems());
		assertEquals(album.getChildrenItems().size(), 0);
		assertEquals(album.getName(), "test");
		assertEquals(album.getId(), 1);
		assertEquals(album.getTheme(), "default");
		assertEquals(album.getParentItem().getName(), "nico");
		assertEquals(album.getSkin(), "default.css");
		assertTrue(album.delete());
		assertFalse(album.exists());
	}
	
	@Test
	public void testModifyAlbum() {
		User user = new User("nico");
		assertTrue (user.exists() && user.isDirectory() && !user.create());
		assertTrue(user.getLogin().equals("nico"));
		assertTrue(user.login("atreides"));
		assertTrue(user.initChildrenItems());
		assertTrue(user.createAlbum("test2"));
		Album album = (Album)user.getChildrenItems().elementAt(1);
		assertTrue (album.exists() && album.isDirectory() && !album.create());
		album.setTheme("testTheme");
		album.setSkin("testCss.css");
		album.update();
		assertEquals(album.getId(), 1);
		assertEquals(album.getTheme(), "testTheme");
		assertEquals(album.getParentItem().getName(), "nico");
		assertEquals(album.getSkin(), "testCss.css");
		assertTrue(album.delete());
		assertFalse(album.exists());
	}
}
